﻿using MVVMDemo01.Base;
using MVVMDemo01.Models;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace MVVMDemo01.ViewModels
{
    public class MainViewModel
    {
        public DataModel dataModel { get; set; } = new DataModel();

        public ObservableCollection<DetailMagModel> DataList { get; set; }

        public ICommand AddCommand { get; set; }

        public MainViewModel()
        {
            DataList = new ObservableCollection<DetailMagModel>();
            AddCommand = new Command(Add);
        }

        public void Add(object? parameter)
        {
            dataModel.Value3 = dataModel.Value1 + dataModel.Value2;
            DetailMagModel detailMagModel = new DetailMagModel();
            detailMagModel.Msg = $"{dataModel.Value1} + {dataModel.Value2} = {dataModel.Value3}";
            detailMagModel.DeleteCommand = new Command(Delete);
            DataList.Add(detailMagModel);
        }

        public void Delete(object? parameter)
        {
            DetailMagModel detailMagModel = (DetailMagModel)parameter;
            DataList.Remove(detailMagModel);
        }
    }
}
